﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace SecureCookie.Implementation.Protocol
{
    /// <summary>
    /// Data only known by the server.
    /// </summary>
    public class ServerSideData
    {
        /// <summary>A secret key to perform the validation</summary>
        public string SecretKey { get; internal set; }
        /// <summary>The maximum cookie lifetime for session based cookies</summary>
        public TimeSpan MaxLifetimeForSessionBasedCookies { get; internal set; }
        /// <summary>
        /// A unique value to identify a client, this value should not be changed during the browser session of the user.
        /// Preferable this value is a secure identification, like a unique value from the SSL session.
        /// </summary>
        public string ClientUniqueValue { get; internal set; }

        /// <summary>
        /// Default constructor
        /// </summary>
        /// <param name="secretKey"><see cref="SecretKey"/></param>
        /// <param name="maxLifetimeForSessionBasedCookies"><see cref="MaxLifetimeForSessionBasedCookies"/></param>
        /// <param name="clientUniqueValue"><see cref="ClientUniqueValue"/></param>
        public ServerSideData(string secretKey, TimeSpan maxLifetimeForSessionBasedCookies, string clientUniqueValue)
        {
            if (string.IsNullOrEmpty(secretKey)) throw new ArgumentNullException("secretKey");
            if (maxLifetimeForSessionBasedCookies == null) throw new ArgumentNullException("maxLifetimeForSessionBasedCookies");
            if (maxLifetimeForSessionBasedCookies == TimeSpan.Zero) throw new ArgumentException("Should be defined", "maxLifetimeForSessionBasedCookies");
            if (string.IsNullOrEmpty(clientUniqueValue)) throw new ArgumentNullException("clientUniqueValue");

            SecretKey = secretKey;
            MaxLifetimeForSessionBasedCookies = maxLifetimeForSessionBasedCookies;
            ClientUniqueValue = clientUniqueValue;
        }
    }
}
